home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
DESDOS.ARJ
/
GETPASS.C
< prev
next >
Wrap
Text File
|
1992-05-15
|
1KB
|
77 lines
#include <stdio.h>
#include <signal.h>
#include <bios.h>
/* Issue prompt and read reply with echo turned off */
char *
getpass(prompt)
char *prompt;
{
#ifndef MSDOS
struct sgttyb ttyb,ttysav;
FILE *tty;
#endif
register char *cp;
int c;
static char pbuf[128];
#ifndef MSDOS
int (*signal())(),(*sig)();
#else
int (*sig)();
#endif
#ifndef MSDOS
if ((tty = fdopen(open(TTY, 2), "r")) == NULL)
tty = stdin;
else
setbuf(tty, (char *)NULL);
#endif
sig = signal(SIGINT, SIG_IGN);
#ifndef MSDOS
ioctl(fileno(tty), TIOCGETP, &ttyb);
ioctl(fileno(tty), TIOCGETP, &ttysav);
ttyb.sg_flags |= RAW;
ttyb.sg_flags &= ~ECHO;
ioctl(fileno(tty), TIOCSETP, &ttyb);
#endif
fprintf(stderr, "%s", prompt);
fflush(stderr);
cp = pbuf;
for (;;) {
#ifndef MSDOS
c = getc(tty);
#else
c = (int) bioskey(0);
#endif
if(c == '\r' || c == '\n' || c == EOF)
break;
if (cp < &pbuf[127])
*cp++ = c;
}
*cp = '\0';
fprintf(stderr,"\r\n");
fflush(stderr);
#ifndef MSDOS
ioctl(fileno(tty), TIOCSETP, &ttysav);
#endif
signal(SIGINT, SIG_IGN);
#ifndef MSDOS
if (tty != stdin)
fclose(tty);
#endif
return(pbuf);
}